<?php 
/**
* 
*/
class UserSocial extends Users
{
	
	public function checkUser($uid, $oauth_provider,$email,$user_birthday,$gender,$user_profile) 
   	 {	        
        	 $result = Users::model()->findByAttributes(array('email'=>$email));
	        if (!empty($result)) {
	        	if(empty($result->oauth_uid))
	          	   Users::model()->updateByPk($result->user_id, array('oauth_uid'=>$uid));

	        } else {
	            #user not present. Insert a new Record
	            $this->oauth_uid = $uid;
	            $this->oauth_provider = $oauth_provider;
	            $this->user_name = strtok($email, '@');
	            $this->email = $email;
	            if ($this->save(false)){
	            
		   UserProfiles::model()->updateByPk($this->user_id, array('full_name'=>$user_profile['name'], 'first_name'=>$user_profile['first_name'], 'last_name'=>$user_profile['last_name']));
	            
	            }
		    $result = Users::model()->findByAttributes(array('oauth_uid'=>$uid,'oauth_provider'=>$oauth_provider));
	            return $result;
	        }
	        return $result;
    }
    public function setGender($gender) {
        switch($gender) {
            case 'male': return 'male';
            case 'female': return 'female';
    	}   
	}
}

 ?>